package com.llp.javaweb.servlet;

import com.google.gson.Gson;
import com.llp.javaweb.pojo.Product;
import com.llp.javaweb.service.ShopCartService;
import com.llp.javaweb.service.impl.ShopCartServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author llp
 * {@code @date} 2022年11月03日15:25
 */
@WebServlet("/cart/shopCart")
public class ShopCartServlet extends HttpServlet {
    ShopCartService shopCartService=new ShopCartServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        /*
        通过用户id获取购物车信息
         */
        String userid = req.getParameter("userid");
       List<Product> userProducts=shopCartService.getAllUserProduct(userid);
//        HttpSession session = req.getSession();
//        session.setAttribute("userProducts",userProducts);
        //进行
        //userProducts.forEach(System.out::println);
        Gson gson=new Gson();
        resp.getWriter().write(gson.toJson(userProducts));

    }
}
